home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / DSKA / hostspec.asm < prev    next >
Encoding:
Assembly Source File  |  1994-08-19  |  9.6 KB  |  294 lines  |  [TEXT/ttxt]

  1.  
  2. ;-----------------------------------------------------------;
  3. ; HOSTSPEC.ASM                            ;
  4. ; Written By: Keith Larson                    ;
  5. ;          TMS320Cxx DSP Applications Engineer        ;
  6. ;          Texas Instruments                 ;
  7. ;                                ;
  8. ; USE WITH THE DSKL [G]RAPH OPTION.  THIS OPTION IS DESIGNED;
  9. ; TO RECEIVE A BYTE FROM THE DSK AND OUTPUT IT GRAPHICLY.   ;
  10. ; RUNNING THIS PROGRAM ON DSKD WILL CRASH THE DEBUGGER!     ;
  11. ;                                ;
  12. ; A spectrum analyzer using the DSK and your Host PC.        ;
  13. ; This code does NOT work with DSKD!  It is run from within ;
  14. ; DSKL using DSK_COMM to send data to the host via the RS232;
  15. ; link.  It is slower than DSK_SPEC, but you do not need an ;
  16. ; oscilliscope!                         ;
  17. ;                                ;
  18. ; To run this program, first assemble it using DSKA.        ;
  19. ; Then start DSKL, select 'X' for load and execute.  Then   ;
  20. ; select 'G' for graphics.  To exit, hit any key (except Q) ;
  21. ; since the keyboard is not flushed and 'Q' will quit DSKL  ;
  22. ; entirely!                            ;
  23. ;-----------------------------------------------------------;
  24. YES    .set    1        ;
  25. NO    .set    0        ;
  26. FFT_S        .set    256    ;
  27. ;-----------------------------------------------------------;
  28. AIC_1        .set    0x0C18    ;TB =TA = 6    0000110000011000=0x0C18
  29. AIC_2        .set    0x0205    ;TA'=TA'= 1    0000001000000101=0x0205
  30. AIC_3        .set    0x264e    ;RB =TB = 0x13 0010011001001110=0x264c 44 khz
  31. AIC_CMD     .set    0x0003    ;   COMMAND    0000000000000011=0x0083
  32. ;-----------------------------------------------------------;
  33. BCMD        .set    0xFA10    ;JUMP CMD
  34. BXMIT        .set    0xFA12    ;JUMP XMIT
  35. BXMIT16     .set    0xFA14    ;JUMP XMIT16
  36. BRECV        .set    0xFA16    ;JUMP RECV
  37. BRECV16     .set    0xFA18    ;JUMP RECV16
  38. BCXMIT        .set    0xFA1A    ;JUMP CXMIT
  39. ;----------------------------------------------------------
  40. STAT1        .set    0x72    ;
  41. ACCU_lo     .set    0x78    ;
  42. ACCU_hi     .set    0x79    ;
  43. REAL        .set    0x7a    ;
  44. IMAG        .set    0x7b    ;
  45. TEMPX        .set    0x7c    ;
  46. AUX0        .set    0x7d
  47. AUX1        .set    0x7e
  48. ;----------------------------------------------------------------
  49. ;    SECONDARY VECTOR TABLE LOACTED IN B0 PROGRAM RAM
  50. ;----------------------------------------------------------------
  51.     .include  "mmregs.inc"    ;     > USERCODE SHOULD NOT OVERWRITE DSKD  <
  52.     .ps    0xfa00        ;     > VECTORS.  ON LOAD, INT2 IS RESTORED <
  53.        ;B    start        ;RS   > BY DSKD, BUT TRAP IS NOT        <
  54.        ;B    start        ;INT0
  55.        ;B    start        ;INT1
  56.        ;B    start        ;INT2  > DSKD LOAD IGNORES INT2 VECTOR
  57.        ;B    start        ;TINT
  58.     .ps    0fa0ah        ;
  59.     B    RINT        ;RINT  Branch to receive interrupt routine
  60.     eint            ;XINT  XINT is only for timing, so just return
  61.     ret            ;
  62.       ; Begin TRAP/DSKD Kernal    ;DSKD load does not restore this code!
  63. ;----------------------------------------------------------------
  64. ;    APPLICATION CODE IS LOCATED ABOVE DSKD KERNAL
  65. ;----------------------------------------------------------------
  66.     .ps    0xFB00        ;
  67.     .entry            ;
  68. ;----------------------------------------------------------------
  69. start:    sxf
  70.     ssxm
  71.     sovm            ; catch accumulator overflows
  72.     ldpk    0        ; All direct addressing is to MMRs and B2
  73.     fort    0        ; Serial port : 16 bit
  74.     rtxm            ;          : ext. FSX
  75.     sfsm            ;          ; burst mode
  76.     lack    0x80        ; AIC reset by pulsing /BR (Global Data)
  77.     sach    DXR        ; send 0 to DXR (AIC)
  78.     sacl    GREG        ; 256 * 100 nS /BR pulse
  79.     lrlk    AR0,0xFFFF    ;
  80.     rptk    255        ; read junk from address 0xFFFF
  81.     lac    *,0,AR0     ;
  82.     conf    1        ; B1,B3 as DRAM if direct bootload
  83. ;--------------------------------
  84. AIC_RS    lack    0x20        ; Turn on XINT
  85.     sacl    IMR        ;
  86.     idle            ;
  87.     lalk    AIC_1        ; Load each AIC configuration word
  88.     call    AIC_2nd     ; and load it into the AIC
  89.     lalk    AIC_2        ;
  90.     call    AIC_2nd     ;
  91.     lalk    AIC_3        ;
  92.     call    AIC_2nd     ;
  93.     lalk    AIC_CMD     ;
  94.     call    AIC_2nd     ;
  95. ;----------------------------------------------------------------
  96.     lark    AR7,0        ; Buffer initialy filled
  97.     lack    0x10        ; AIC RINT
  98.     sacl    IMR        ; where INT0 indicates EOC (End Of Conv)
  99.     ;---------------------------------------------------------------
  100.     lark    AR7,0        ; Buffer initialy filled
  101. FFT:    lrlk    AR0,FFT_S/2    ;
  102.     larp    AR0        ; start FFT with AR0=FFTSize
  103. new_stg lrlk    AR1,_D_base    ; AR1 is the TOP BFLY address
  104.     lrlk    AR2,_D_base    ; AR2 is the BOT BFLY address
  105.     lrlk    AR3,_T_base+1    ; AR3 is the TWiddle pointer
  106.     lrlk    AR4,FFT_S/2    ; AR4 counts DFT blocks
  107.     b    n_DFT2,*,AR1    ;
  108. DFT:    mar    *BR0+,AR5    ; complete circular buffer for TW's
  109.     lark    AR5,1        ; set up DFT loop with *BR0+/BANZ
  110.     mar    *BR0+,AR1    ; using 1 cuts *BR0+ loop in half!
  111.     ;----------------------------------------
  112.     ; AR1=Top AR2=Bottom AR3=Twiddle
  113.     ;----------------------------------------
  114. BFLY:    lac    *,14,AR2    ;(imag1+imag2)/4
  115.     add    *,14,AR1    ;
  116.     sach    *+,1,AR2    ;store TOP imag
  117.     sub    *,15        ;(imag1-imag2)/2
  118.     sach    *+,1,AR1    ;store BOT imag
  119.     lac    *,14,AR2    ;(real1+real2)/4
  120.     add    *,14,AR1    ;
  121.     sach    *+,1,AR2    ;store TOP real
  122.     sub    *,15        ;(real1-real2)/2
  123.     sach    *,1,AR5     ;store BOT real
  124.     banz    OK,*BR0+,AR3    ;If at DFT end quit early
  125.     ;------------------------
  126.     mar    *+,AR2        ;clean up TW base (xxx0000+1)
  127.     mar    *+        ;modify BOTom DATA pointer
  128.     mar    *0+        ;
  129.     mar    *0+,AR1     ;
  130. n_DFT2: mar    *0+        ;modify the TOP pointer
  131.     mar    *0+,AR4     ;
  132.     banz    DFT,*0-,AR3    ;dec DFT block count AR4 by OFFset
  133.     larp    AR0        ;
  134.     mar    *BR0+        ;
  135.     banz    new_stg,*    ;if OFFset was 1, now cleared
  136.     b    endFFT        ;
  137.      ;-------------------------
  138. OK    lt    *-,AR2        ;TREG=TWR     *NOTE* Twiddles are Q15
  139.     mpy    *-        ;PREG=REAL*TWR
  140.     ltp    *+,AR3        ;TREG=IMAG     ACCU=REAL*TWR
  141.     mpy    *        ;PREG=IMAG*TWI              AR2=R AR3=I
  142.     lts    *+,AR2        ;TREG=TWI      ACCU=REAL*TWR-IMAG*TWI
  143.     mpy    *        ;PREG=REAL*TWI
  144.     sach    *-,1,AR2     ;<<;
  145.     ltp    *,AR3        ;TREG=IMAG     ACCU=REAL*TWI
  146.     mpy    *BR0+,AR2    ;PREG=IMAG*TWR
  147.     apac            ;           ACCU=IMAG*TWR+REAL*TWI
  148.     sach    *+,1,AR2     ;<<;
  149.     b    BFLY,*+,AR1    ;
  150.     ;------------------------------------------------------------
  151. endFFT: larp    AR2        ;Transform REAL & IMAG to log magnitude
  152.     lrlk    AR2,_D_base    ;AR3=FFT data pointer
  153.     lrlk    AR3,FFT_S-1    ;AR5=FFT loop counter
  154.     lrlk    AR0,FFT_S
  155.     ;-----------------------------------------------------------;
  156.     ; WINDOW: Performs post FFT raised cosine windowing!        ;
  157.     ; This is done by using the frequency coefficients of the   ;
  158.     ; window in a convolution filter of the spectrum.        ;
  159.     ;-----------------------------------------------------------;
  160.       ;mar    *BR0+           ; don't start at DC
  161. more_MAG
  162.     mar     *BR0-        ;  -IMAG[-1]  1-COS(nwt/N)     + 1
  163.     lac     *BR0+,15    ;   IMAG[-0]  filter by post     |
  164.     subh     *BR0+        ;  +IMAG[+1]  convolution    <--+++-->
  165.     add     *BR0-,15    ;   IMAG            + + -.5
  166.     sach     IMAG        ;
  167.     mar     *+        ;   REAL
  168.     mar     *BR0-        ;  -REAL[-1]
  169.     lac     *BR0+,15    ;   REAL[-0]  X[-1] -2*X[0] + X[1]
  170.     subh     *BR0+        ;  +REAL[+1]
  171.     add     *BR0-,15,AR1    ;   REAL
  172.     sach     REAL        ;
  173.     sqra    IMAG        ;IMAG & REAL can be at most 0x7fff Q15
  174.     ltp    REAL        ;MPY will result (at most) in max positive
  175.     mpy    REAL        ;
  176.     apac            ;output is positive Q30
  177.     addk    0x1        ;Set up a floor value; log(0) not legal!
  178.     lark    AR1,22        ;pre-scaling exponent shifts Y axis
  179.     rptk    31        ;
  180.     norm    *-        ;
  181.     larp    AR2        ;
  182.     mar    *BR0-      ;-REAL;dump log(f) into oldest REAL (odd addr)
  183.     sach    *,2        ;clr explicit 1.0 and sign bit from mant
  184.     zals    *        ;load into ACCU_lo
  185.     sar    AR1,*        ;then append exponent (AR1)
  186.     addh    *        ;
  187.     rptk    10        ;jam result into ACCU_hi
  188.     sfl            ;If needed, Use ADDH to saturate overflow
  189.      ;    sach    *        ;
  190.      ;    addh    *        ;
  191.     sach    *        ;
  192.     lac    *        ;
  193.     andk    0xfffc,0    ;
  194.     sacl    *BR0+        ; REAL
  195.     mar    *-        ; IMAG
  196.     mar    *BR0+,AR3    ;+IMAG
  197.     banz    more_MAG,*-,AR2 ;keep going until all done
  198.     ;--------------------------------------------------------
  199. BITREV: lrlk    AR0,FFT_S    ;Now perform Output bit reversal
  200.     lrlk    AR1,_D_base    ;by moving the magnitude, which
  201.     lrlk    AR2,_D_base+1    ;is in the REAL slots, into the
  202.     lrlk    AR3,FFT_S-1    ;IMAG slots of the FFT data array
  203. more_BR lac    *+        ;load the magnitude
  204.     mar    *+,AR1        ;
  205.     sacl    *BR0+,0,AR3    ;move it to an open IMAG slot
  206.     banz    more_BR,*-,AR2    ;more data to move?
  207.     ;--------------------------------------------------------
  208. MOVE_IO larp    AR7        ;wait until buffer is full
  209.     banz    MOVE_IO,*,AR2    ;(AR7 is decremented by ISR)
  210.     ;------------------------
  211.     lrlk    AR3,_D_base    ;AR3=FFT data pointer
  212.     lrlk    AR4,_B_base    ;AR4=BUFF data pointer
  213.     lrlk    AR5,FFT_S-1    ;AR5=FFT loop counter
  214.     lrlk    AR6,_B_base    ;AR6=ISR BUFF data pointer
  215.     lrlk    AR7,FFT_S-1    ;AR7=ISR BUFF loop counter
  216.     ;-------------------------
  217.     dint
  218.     zac
  219.     call    DAT2HOST
  220.     larp    AR2
  221. more_IO
  222.     lar    AR2,*,AR3    ;Get A/D value from buffer
  223.     lac    *,0,AR4     ;ACCU= log magnitude (from even address)
  224.     sacl    *+,0,AR3    ;
  225.  
  226.     rptk    7
  227.     sfr
  228.     ork    1
  229.     call    DAT2HOST
  230.     larp    AR3
  231.  
  232.     zac            ;
  233.     sach    *+,0        ;IMAG=0
  234.     sar    AR2,*+,AR5    ;
  235.  
  236.     banz    more_IO,*-,AR4    ;
  237.     eint            ; BUFF clear so enable INT's
  238.     b    FFT        ;
  239. ;-----------------------------------------------------------------
  240. RINT:    sst1    STAT1        ;Recover ARP from ARB by LST1 last
  241.     larp    AR7        ;AR6 = current buffer position
  242.     banz    more_buf,*-,AR6 ;if buffer is full RET w/o EINT
  243.     lark    AR7,0        ;
  244.     lst1    STAT1        ;
  245.     ret            ;
  246. more_buf            ;
  247.     sacl    ACCU_lo     ;Use NORM start val to adj Y offset
  248.     sach    ACCU_hi     ;post log convert scaling ajsts magnitude
  249.     zalh    *        ;Get value
  250.     sach    DXR        ;
  251.     ;------------------------
  252.     lac    DRR        ;
  253.     bit    TEMPX,15    ;Inverting every other input aliases the
  254.     bbz    NO_NVRT     ;frequency domain, swapping DC and Nyquist!
  255.     neg            ;
  256. NO_NVRT             ;
  257.     sacl    *+        ;<<< store DRR, and point to next
  258.     lac    TEMPX        ;
  259.     xork    1        ;
  260.     sacl    TEMPX        ;
  261.     zalh    ACCU_hi     ;
  262.     adds    ACCU_lo     ;
  263.     lst1    STAT1        ;
  264.     eint            ;
  265.     ret            ;
  266. ******************************************************************
  267. AIC_2nd adlk    6,15        ;set ACCU_hi = 3 for secondary XMIT
  268.     idle            ;Wait for a XINT
  269.     sach    DXR        ;
  270.     idle            ;ACCU_hi requests 2nd XMIT
  271.     sacl    DXR        ;
  272.     idle            ;ACCU_lo sets up registers
  273.     sacl    DXR,2        ;close command with LSB = 00
  274.     idle            ;
  275.     eint            ;
  276.     ret            ;
  277. ********************************************************************
  278. DAT2HOST sacl      ACCU_lo    ;
  279.      sach      ACCU_hi    ;
  280.      sar      AR0,AUX0    ;
  281.      sar      AR1,AUX1    ;
  282.      call      BXMIT     ;
  283.      zals      ACCU_lo    ;
  284.      addh      ACCU_hi    ;
  285.      lar      AR0,AUX0    ;
  286.      lar      AR1,AUX1    ;
  287.      ret            ;
  288. ;====================================================================
  289.     .listoff        ;
  290.     .ds    0x400        ;NOTE: Twiddles are relocated to
  291.     .include "dsk_twid.inc" ;      0x400 (B2) using CONF 1
  292.     .liston
  293.     .end
  294.